import java.util.*;
import java.io.*;
public class UnionFindLuogu {
    //洛谷版本的简单递归版并查集
    //https://www.luogu.com.cn/record/191775501
    public static int MAX = 10001;
    public static int[] farther = new int[MAX];
    public static int set;
    public static void build(int n){
        set = n;
        for (int i = 1; i <= n; i++) {
            farther[i] = i;
        }
    }
    public static int find(int n){
        if(n != farther[n]){
            farther[n] = find(farther[n]);
        }
        return farther[n];
    }
    public static boolean isSameSet(int a, int b){
        return find(a) == find(b);
    }

    public static void union(int a,int b){
        int fa = find(a);
        int fb = find(b);
        if(fa != fb){
            farther[fa] = fb;
        }
    }
    public static PrintWriter out = new PrintWriter(new BufferedWriter(new OutputStreamWriter(System.out)));
    public static Read sc = new Read();
    public static void main(String[] args) throws IOException{
        int n = sc.nextInt();
        int k = sc.nextInt();
        build(n);
        while(k-- > 0){
            int a = sc.nextInt();
            int b = sc.nextInt();
            int c = sc.nextInt();
            if(a == 1){
                union(b,c);
            }else{
                out.println(isSameSet(b, c) ? "Y" : "N");
            }
        }
        out.flush();
        out.close();
    }
}
class Read{
    StringTokenizer st = new StringTokenizer("");
    BufferedReader bf = new BufferedReader(new InputStreamReader(System.in));
    String next() throws IOException{
        while(!st.hasMoreTokens()){
            st = new StringTokenizer(bf.readLine());
        }
        return st.nextToken();
    }

    String nextLine() throws IOException{
        return bf.readLine();
    }

    int nextInt() throws IOException{
        return Integer.parseInt(next());
    }

    long nextLong() throws IOException{
        return Long.parseLong(next());
    }

    double nextDouble() throws IOException{
        return Double.parseDouble(next());
    }
}
